package lambda.匿名对象;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by ydw on 2017/6/26.
 */
public class Lambda {
    public static void main(String[] args) {
        Lambda lambda = new Lambda();
        lambda.oldSort();
        lambda.newSort();
    }
    public void oldSort(){
        List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");

        Collections.sort(names, new Comparator<String>() {
            @Override
            public int compare(String a, String b) {
                return b.compareTo(a);
            }
        });
        System.out.println(names);
    }

    public void newSort(){
        List<String> names = Arrays.asList("peter", "anna", "mike", "xenia");

        //作为一个匿名对象(比较器)用lambda表达式来使用.
        Collections.sort(names, (a, b) -> b.compareTo(a));

        //最原始的lambda表达式
        Collections.sort(names, (String a, String b) -> {
            return b.compareTo(a);
        });

        System.out.println(names);
    }
}
